---
title: literal
description: Creates a literal schema.
source: /schemas/literal/literal.ts
contributors:
  - fabian-hiller
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# literal

Creates a literal schema.

```ts
const Schema = v.literal<TLiteral, TMessage>(literal, message);
```

## Generics

- `TLiteral` <Property {...properties.TLiteral} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `literal` <Property {...properties.literal} />
- `message` <Property {...properties.message} />

### Explanation

With `literal` you can validate that the input matches a specified value. If the input is invalid, you can use `message` to customize the error message.

## Returns

- `Schema` <Property {...properties.Schema} />

## Examples

The following examples show how `literal` can be used.

### String literal

Schema to validate a string literal.

```ts
const StringLiteralSchema = v.literal('foo');
```

### Number literal

Schema to validate a number literal.

```ts
const NumberLiteralSchema = v.literal(26);
```

### Boolean literal

Schema to validate a boolean literal.

```ts
const BooleanLiteralSchema = v.literal(true);
```

## Related

The following APIs can be combined with `literal`.

### Schemas

<ApiList
  items={[
    'array',
    'exactOptional',
    'intersect',
    'lazy',
    'looseObject',
    'looseTuple',
    'map',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'nullable',
    'nullish',
    'object',
    'objectWithRest',
    'optional',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'tuple',
    'tupleWithRest',
    'undefinedable',
    'union',
  ]}
/>

### Methods

<ApiList
  items={[
    'assert',
    'config',
    'fallback',
    'getDefault',
    'getDefaults',
    'getFallback',
    'getFallbacks',
    'is',
    'message',
    'parse',
    'parser',
    'pipe',
    'safeParse',
    'safeParser',
  ]}
/>

### Actions

<ApiList
  items={[
    'check',
    'brand',
    'description',
    'flavor',
    'metadata',
    'rawCheck',
    'rawTransform',
    'readonly',
    'title',
    'transform',
  ]}
/>

### Utils

<ApiList items={['entriesFromList', 'isOfKind', 'isOfType']} />
